<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		
	<span class="different-posts different-posts_earlier">📖 <a href="/page/2">earlier posts</a> 📖</span>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/2. zabbix 服务端安装/">zabbix 服务端安装</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;zabbix 是另外一个用得比较多的监控工具，同样也需要 apache+php 的支持，但它比 nagios 要多一个 mysql ，因为它有数据需要储存。所以，安装 zabbix，必须要安装 mysql 。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在安装 zabbix 之前，也需要安装 epel 扩展源，因为 centos 自带 yum 源是没有 zabbix 的。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># yum install -y epel-release</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装 rpm 包的 lamp 环境</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># yum install -y httpd mysql mysql-libs php php-mysql mysql-server php-bcmath php-gd php-mbstring</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装 zabbix 服务端</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># yum install -y zabbix30 zabbix30-agent zabbix30-server zabbix30-server-mysql zabbix30-web zabbix30-web-mysql net-snmp-devel</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装好以后，就可以启动服务了</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># service zabbix-server start</span></div><div class="line">[root@zabbix ~]<span class="comment"># service zabbix-agent start</span></div><div class="line">[root@zabbix ~]<span class="comment"># service httpd start</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改一下 mysql 配置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># vim /etc/my.cnf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改或增加内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[mysql]</div><div class="line">default-character-set = utf8</div><div class="line">[mysqld]</div><div class="line">character_set_server = utf8</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后启动 mysql 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># /etc/init.d/mysqld start</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后建库，导入数据</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># mysql -uroot -e "create database zabbix"</span></div><div class="line">[root@zabbix ~]<span class="comment"># mysql -uroot --default-character-set=utf8 zabbix &lt; /usr/share/zabbix-mysql/schema.sql</span></div><div class="line">[root@zabbix ~]<span class="comment"># mysql -uroot --default-character-set=utf8 zabbix &lt; /usr/share/zabbix-mysql/images.sql </span></div><div class="line">[root@zabbix ~]<span class="comment"># mysql -uroot --default-character-set=utf8 zabbix &lt; /usr/share/zabbix-mysql/data.sql</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这时发现 zabbix_server 并没有启动起来</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># mysql -uroot -e "grant all on *.* to 'zabbix'@'localhost' identified by 'zabbix';"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 /etc/zabbix/zabbix_server.conf </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># vim /etc/zabbix/zabbix_server.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置 DBUser，DBPasseord </p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/01.png?raw=true" alt="01"><figcaption class="figure__caption">01</figcaption></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/02.png?raw=true" alt="02"><figcaption class="figure__caption">02</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后重启 zabbix-server 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># /etc/init.d/zabbix-server restart</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;再次查看 zabbix_server 服务已启动</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/03.png?raw=true" alt="03"><figcaption class="figure__caption">03</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面通过浏览器安装 zabbix</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;浏览器访问 <a href="http://ip/zabbix" target="_blank" rel="external">http://ip/zabbix</a> ，默认会有 “It is not safe to rely on the system‘s timezone settings ” 这样的警告信息</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/04.png?raw=true" alt="04"><figcaption class="figure__caption">04</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需要</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># vim /etc/php.ini</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/05.png?raw=true" alt="05"><figcaption class="figure__caption">05</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/06.png?raw=true" alt="06"><figcaption class="figure__caption">06</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;点 next，会提示有一些参数不合适，需要通过编辑配置文件 /etc/php.ini ，解决相关的报错信息</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/07.png?raw=true" alt="07"><figcaption class="figure__caption">07</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;更改完成，重启 apache 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@zabbix ~]<span class="comment"># service httpd restart</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;点 retry，所有参数提示 OK</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/08.png?raw=true" alt="08"><figcaption class="figure__caption">08</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;点 next</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/09.png?raw=true" alt="09"><figcaption class="figure__caption">09</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;输入 mysql 相关配置，点  test connection 测试</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/10.png?raw=true" alt="10"><figcaption class="figure__caption">10</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;显示 OK，点 next</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/11.png?raw=true" alt="11"><figcaption class="figure__caption">11</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Name 写 127.0.0.1 （这个可以自定义）</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/12.png?raw=true" alt="12"><figcaption class="figure__caption">12</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;继续点 next</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/13.png?raw=true" alt="13"><figcaption class="figure__caption">13</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;再点 next</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/14.png?raw=true" alt="14"><figcaption class="figure__caption">14</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;点 finish ，进入登录页面，默认帐号 admin 密码 zabbix</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/15.png?raw=true" alt="15"><figcaption class="figure__caption">15</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;输入帐号密码登录</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/16.png?raw=true" alt="16"><figcaption class="figure__caption">16</figcaption></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/19. zabbix进行数据库备份以及表分区/">zabbix进行数据库备份以及表分区</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;由于测试环境上面使用的zabbix服务器配置比较低，经常会遇到性能瓶颈（主要是数据库和磁盘I/O等），于是倒逼我使用了一些方式来缓解这些问题。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;主要是以前使用的那个备份数据库的脚本是对zabbix数据库进行全备的，使用的又是mysql自带的工具mysqldump，当数据量大了之后进行全备所花的时间比较长，这样将会造成数据库的锁读。。。从而使zabbix服务以为mysql死掉了，产生一大堆的报警。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;后来发现原来造成数据库数据量大量增加的是zabbix数据库中的一些存储数据的大表导致的。于是备份数据库的时候可以选择跳过这些表进行备份，这样，将大大减少数据库备份所花的时间（PS：之前备份数据库所花时间在十分钟左右，现在跳过大表备份，所花时间在1S左右就能备份完，大大缩短了备份数据库时间）。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面就贴出某位大神写的专门为zabbix数据库做备份以及恢复的脚本：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/bin/bash</span></div><div class="line"><span class="comment">#author: itnihao</span></div><div class="line">red=<span class="string">'\e[0;31m'</span> <span class="comment"># 红色 </span></div><div class="line">RED=<span class="string">'\e[1;31m'</span> </div><div class="line">green=<span class="string">'\e[0;32m'</span> <span class="comment"># 绿色 </span></div><div class="line">GREEN=<span class="string">'\e[1;32m'</span> </div><div class="line">blue=<span class="string">'\e[0;34m'</span> <span class="comment"># 蓝色 </span></div><div class="line">BLUE=<span class="string">'\e[1;34m'</span> </div><div class="line">purple=<span class="string">'\e[0;35m'</span> <span class="comment"># 紫色 </span></div><div class="line">PURPLE=<span class="string">'\e[1;35m'</span> </div><div class="line">NC=<span class="string">'\e[0m'</span> <span class="comment"># 没有颜色 </span></div><div class="line"><span class="built_in">source</span> /etc/bashrc</div><div class="line"><span class="built_in">source</span> /etc/profile</div><div class="line">MySQL_USER=zabbix</div><div class="line">MySQL_PASSWORD=zabbix</div><div class="line">MySQL_HOST=localhost</div><div class="line">MySQL_PORT=3306</div><div class="line">MySQL_DUMP_PATH=/opt/backup</div><div class="line">MYSQL_BIN_PATH=/opt/software/mysql/bin/mysql</div><div class="line">MYSQL_DUMP_BIN_PATH=/opt/software/mysql/bin/mysqldump</div><div class="line">MySQL_DATABASE_NAME=zabbix</div><div class="line">DATE=$(date <span class="string">'+%Y%m%d'</span>)</div><div class="line"><span class="function"><span class="title">MySQLDUMP</span></span> () &#123;</div><div class="line"> [ -d <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span> ] || mkdir <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span></div><div class="line"> <span class="built_in">cd</span> <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span></div><div class="line"> [ -d logs ] || mkdir logs</div><div class="line"> [ -d <span class="variable">$&#123;DATE&#125;</span> ] || mkdir <span class="variable">$&#123;DATE&#125;</span></div><div class="line"> <span class="built_in">cd</span> <span class="variable">$&#123;DATE&#125;</span></div><div class="line">  </div><div class="line"> <span class="comment">#TABLE_NAME_ALL=$($&#123;MYSQL_BIN_PATH&#125; -u$&#123;MySQL_USER&#125; -p$&#123;MySQL_PASSWORD&#125; -h$&#123;MySQL_HOST&#125; $&#123;MySQL_DATABASE_NAME&#125; -e "show tables"|egrep -v "(Tables_in_zabbix)")</span></div><div class="line"> TABLE_NAME_ALL=$(<span class="variable">$&#123;MYSQL_BIN_PATH&#125;</span> -u<span class="variable">$&#123;MySQL_USER&#125;</span> -p<span class="variable">$&#123;MySQL_PASSWORD&#125;</span> -h<span class="variable">$&#123;MySQL_HOST&#125;</span> <span class="variable">$&#123;MySQL_DATABASE_NAME&#125;</span> -e <span class="string">"show tables"</span>|egrep -v <span class="string">"(Tables_in_zabbix|history*|trends*|acknowledges|alerts|auditlog|events|service_alarms)"</span>)</div><div class="line"> <span class="keyword">for</span> TABLE_NAME <span class="keyword">in</span> <span class="variable">$&#123;TABLE_NAME_ALL&#125;</span></div><div class="line"> <span class="keyword">do</span></div><div class="line"> <span class="variable">$&#123;MYSQL_DUMP_BIN_PATH&#125;</span> --opt -u<span class="variable">$&#123;MySQL_USER&#125;</span> -p<span class="variable">$&#123;MySQL_PASSWORD&#125;</span> -P<span class="variable">$&#123;MySQL_PORT&#125;</span> -h<span class="variable">$&#123;MySQL_HOST&#125;</span> <span class="variable">$&#123;MySQL_DATABASE_NAME&#125;</span> <span class="variable">$&#123;TABLE_NAME&#125;</span> &gt;<span class="variable">$&#123;TABLE_NAME&#125;</span>.sql</div><div class="line"> sleep 0.01</div><div class="line"> <span class="keyword">done</span></div><div class="line"> [ <span class="string">"$?"</span> == 0 ] &amp;&amp; <span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;DATE&#125;</span>: Backup zabbix succeed"</span> &gt;&gt; <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span>/logs/ZabbixMysqlDump.log</div><div class="line"> [ <span class="string">"$?"</span> != 0 ] &amp;&amp; <span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;DATE&#125;</span>: Backup zabbix not succeed"</span> &gt;&gt; <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span>/logs/ZabbixMysqlDump.log</div><div class="line">  </div><div class="line"> <span class="built_in">cd</span> <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span>/</div><div class="line"> rm -rf $(date +%Y%m%d --date=<span class="string">'5 days ago'</span>)</div><div class="line"> <span class="built_in">exit</span> 0</div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">MySQLImport</span></span> () &#123;</div><div class="line"> <span class="built_in">cd</span> <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span></div><div class="line"> DATE=$(ls <span class="variable">$&#123;MySQL_DUMP_PATH&#125;</span> |egrep <span class="string">"\b^[0-9]+$\b"</span>)</div><div class="line"> <span class="built_in">echo</span> -e <span class="string">"<span class="variable">$&#123;green&#125;</span><span class="variable">$&#123;DATE&#125;</span>"</span></div><div class="line"> <span class="built_in">echo</span> -e <span class="string">"<span class="variable">$&#123;blue&#125;</span>what DATE do you want to import,please input date:<span class="variable">$&#123;NC&#125;</span>"</span></div><div class="line"> <span class="built_in">read</span> SELECT_DATE</div><div class="line"> <span class="keyword">if</span> [ -d <span class="string">"<span class="variable">$&#123;SELECT_DATE&#125;</span>"</span> ];<span class="keyword">then</span></div><div class="line"> <span class="built_in">echo</span> -e <span class="string">"you select is <span class="variable">$&#123;green&#125;</span><span class="variable">$&#123;SELECT_DATE&#125;</span><span class="variable">$&#123;NC&#125;</span>, do you want to contine,if,input <span class="variable">$&#123;red&#125;</span>(yes|y|Y)<span class="variable">$&#123;NC&#125;</span>,else then exit"</span></div><div class="line"> <span class="built_in">read</span> Input</div><div class="line"> [[ <span class="string">'yes|y|Y'</span> =~ <span class="string">"<span class="variable">$&#123;Input&#125;</span>"</span> ]]</div><div class="line"> status=<span class="string">"$?"</span></div><div class="line"> <span class="keyword">if</span> [ <span class="string">"<span class="variable">$&#123;status&#125;</span>"</span> == <span class="string">"0"</span> ];<span class="keyword">then</span></div><div class="line"> <span class="built_in">echo</span> <span class="string">"now import SQL....... Please wait......."</span></div><div class="line"> <span class="keyword">else</span></div><div class="line"> <span class="built_in">exit</span> 1</div><div class="line"> <span class="keyword">fi</span></div><div class="line"> <span class="built_in">cd</span> <span class="variable">$&#123;SELECT_DATE&#125;</span></div><div class="line"> <span class="keyword">for</span> PER_TABEL_SQL <span class="keyword">in</span> $(ls *.sql)</div><div class="line"> <span class="keyword">do</span></div><div class="line"> <span class="variable">$&#123;MYSQL_BIN_PATH&#125;</span> -u<span class="variable">$&#123;MySQL_USER&#125;</span> -p<span class="variable">$&#123;MySQL_PASSWORD&#125;</span> -h<span class="variable">$&#123;MySQL_HOST&#125;</span> <span class="variable">$&#123;MySQL_DATABASE_NAME&#125;</span> &lt; <span class="variable">$&#123;PER_TABEL_SQL&#125;</span></div><div class="line"> <span class="built_in">echo</span> -e <span class="string">"import <span class="variable">$&#123;PER_TABEL_SQL&#125;</span> <span class="variable">$&#123;PURPLE&#125;</span>........................<span class="variable">$&#123;NC&#125;</span>"</span></div><div class="line"> <span class="keyword">done</span> </div><div class="line"> <span class="built_in">echo</span> <span class="string">"Finish import SQL,Please check Zabbix database"</span></div><div class="line"> <span class="keyword">else</span> </div><div class="line"> <span class="built_in">echo</span> <span class="string">"Don't exist <span class="variable">$&#123;SELECT_DATE&#125;</span> DIR"</span> </div><div class="line"> <span class="keyword">fi</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">case</span> <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span></div><div class="line">MySQLDUMP|mysqldump)</div><div class="line"> MySQLDUMP</div><div class="line"> ;;</div><div class="line">MySQLImport|mysqlimport)</div><div class="line"> MySQLImport</div><div class="line"> ;;</div><div class="line">*)</div><div class="line"> <span class="built_in">echo</span> <span class="string">"Usage: <span class="variable">$0</span> &#123;(MySQLDUMP|mysqldump) (MySQLImport|mysqlimport)&#125;"</span></div><div class="line"> ;;</div><div class="line"><span class="keyword">esac</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该脚本源出处在这<a href="https://github.com/itnihao/zabbix-book/blob/master/03-chapter/Zabbix_MySQLdump_per_table_v2.sh" target="_blank" rel="external">https://github.com/itnihao/zabbix-book/blob/master/03-chapter/Zabbix_MySQLdump_per_table_v2.sh</a></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这是在大神的脚本上做了修改之后形成的适合我自己备份的脚本，各位也可以自行修改成适合自己的备份脚本。这个脚本实现的效果上面已经说了，之前做全备的时候差不多有4G左右的数据量，现在只备份配置文件数据量只有不到10M，果断大大节省时间以及空间呀。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;不过这样的话将无法保证数据的备份，目前考虑使用xtradbbackup对数据进行增量备份，目前还未实现，留待过两天做吧。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;好了，关于数据库备份的事情搞了，然后还需要对大数据量的表进行表分区，参考了zabbix官网的一篇文章<a href="https://www.zabbix.org/wiki/Docs/howto/mysql_partition" target="_blank" rel="external">https://www.zabbix.org/wiki/Docs/howto/mysql_partition</a> 各位有兴趣的话可以去看看，我这里将其总结在了一起，更加方便一点。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;表分区可以对大数据量的表进行物理上的拆分成多个文件，但是逻辑上来看，还是一张表，对应用程序是透明的。另外，将这一张大表拆分成很多小表的话将使得数据查询速度能够更快。还可以随时删除旧的数据分区，删除过期数据。这种方式适用于大数据量的表，但是查询量比较少的应用场景。如果是大数据量的表，又有大量查询的话建议还是进行分库分表操作。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先，登录数据库(PS:这个就不演示了)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后登陆到zabbix库中修改两张表的结构：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">use zabbix;</div><div class="line">Alter table history_text drop primary key, add index (id), drop index history_text_2, add index history_text_2 (itemid, id);</div><div class="line">Alter table history_log drop primary key, add index (id), drop index history_log_2, add index history_log_2 (itemid, id);</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改完之后再按照官网上的过程创建四个存储过程：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line">DELIMITER $$</div><div class="line">CREATE PROCEDURE `partition_create`(SCHEMANAME VARCHAR(64), TABLENAME VARCHAR(64), PARTITIONNAME VARCHAR(64), CLOCK INT)</div><div class="line">BEGIN</div><div class="line"> /*</div><div class="line"> SCHEMANAME = The DB schema <span class="keyword">in</span> <span class="built_in">which</span> to make changes</div><div class="line"> TABLENAME = The table with partitions to potentially delete</div><div class="line"> PARTITIONNAME = The name of the partition to create</div><div class="line"> */</div><div class="line"> /*</div><div class="line"> Verify that the partition does not already exist</div><div class="line"> */</div><div class="line">  </div><div class="line"> DECLARE RETROWS INT;</div><div class="line"> SELECT COUNT(1) INTO RETROWS</div><div class="line"> FROM information_schema.partitions</div><div class="line"> WHERE table_schema = SCHEMANAME AND TABLE_NAME = TABLENAME AND partition_description &gt;= CLOCK;</div><div class="line">  </div><div class="line"> IF RETROWS = 0 THEN</div><div class="line"> /*</div><div class="line"> 1. Print a message indicating that a partition was created.</div><div class="line"> 2. Create the SQL to create the partition.</div><div class="line"> 3. Execute the SQL from <span class="comment">#2.</span></div><div class="line"> */</div><div class="line"> SELECT CONCAT( <span class="string">"partition_create("</span>, SCHEMANAME, <span class="string">","</span>, TABLENAME, <span class="string">","</span>, PARTITIONNAME, <span class="string">","</span>, CLOCK, <span class="string">")"</span> ) AS msg;</div><div class="line"> SET @SQL = CONCAT( <span class="string">'ALTER TABLE '</span>, SCHEMANAME, <span class="string">'.'</span>, TABLENAME, <span class="string">' ADD PARTITION (PARTITION '</span>, PARTITIONNAME, <span class="string">' VALUES LESS THAN ('</span>, CLOCK, <span class="string">'));'</span> );</div><div class="line"> PREPARE STMT FROM @SQL;</div><div class="line"> EXECUTE STMT;</div><div class="line"> DEALLOCATE PREPARE STMT;</div><div class="line"> END IF;</div><div class="line">END</div><div class="line">$<span class="variable">$DELIMITER</span> ;</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div></pre></td><td class="code"><pre><div class="line">DELIMITER $$</div><div class="line">CREATE PROCEDURE `partition_drop`(SCHEMANAME VARCHAR(64), TABLENAME VARCHAR(64), DELETE_BELOW_PARTITION_DATE BIGINT)</div><div class="line">BEGIN</div><div class="line"> /*</div><div class="line"> SCHEMANAME = The DB schema <span class="keyword">in</span> <span class="built_in">which</span> to make changes</div><div class="line"> TABLENAME = The table with partitions to potentially delete</div><div class="line"> DELETE_BELOW_PARTITION_DATE = Delete any partitions with names that are dates older than this one (yyyy-mm-dd)</div><div class="line"> */</div><div class="line"> DECLARE <span class="keyword">done</span> INT DEFAULT FALSE;</div><div class="line"> DECLARE drop_part_name VARCHAR(16);</div><div class="line">  </div><div class="line"> /*</div><div class="line"> Get a list of all the partitions that are older than the date</div><div class="line"> <span class="keyword">in</span> DELETE_BELOW_PARTITION_DATE. All partitions are prefixed with</div><div class="line"> a <span class="string">"p"</span>, so use SUBSTRING TO get rid of that character.</div><div class="line"> */</div><div class="line"> DECLARE myCursor CURSOR FOR</div><div class="line"> SELECT partition_name</div><div class="line"> FROM information_schema.partitions</div><div class="line"> WHERE table_schema = SCHEMANAME AND TABLE_NAME = TABLENAME AND CAST(SUBSTRING(partition_name FROM 2) AS UNSIGNED) &lt; DELETE_BELOW_PARTITION_DATE;</div><div class="line"> DECLARE CONTINUE HANDLER FOR NOT FOUND SET <span class="keyword">done</span> = TRUE;</div><div class="line">  </div><div class="line"> /*</div><div class="line"> Create the basics <span class="keyword">for</span> when we need to drop the partition. Also, create</div><div class="line"> @drop_partitions to hold a comma-delimited list of all partitions that</div><div class="line"> should be deleted.</div><div class="line"> */</div><div class="line"> SET @alter_header = CONCAT(<span class="string">"ALTER TABLE "</span>, SCHEMANAME, <span class="string">"."</span>, TABLENAME, <span class="string">" DROP PARTITION "</span>);</div><div class="line"> SET @drop_partitions = <span class="string">""</span>;</div><div class="line">  </div><div class="line"> /*</div><div class="line"> Start looping through all the partitions that are too old.</div><div class="line"> */</div><div class="line"> OPEN myCursor;</div><div class="line"> read_loop: LOOP</div><div class="line"> FETCH myCursor INTO drop_part_name;</div><div class="line"> IF <span class="keyword">done</span> THEN</div><div class="line"> LEAVE read_loop;</div><div class="line"> END IF;</div><div class="line"> SET @drop_partitions = IF(@drop_partitions = <span class="string">""</span>, drop_part_name, CONCAT(@drop_partitions, <span class="string">","</span>, drop_part_name));</div><div class="line"> END LOOP;</div><div class="line"> IF @drop_partitions != <span class="string">""</span> THEN</div><div class="line"> /*</div><div class="line"> 1. Build the SQL to drop all the necessary partitions.</div><div class="line"> 2. Run the SQL to drop the partitions.</div><div class="line"> 3. Print out the table partitions that were deleted.</div><div class="line"> */</div><div class="line"> SET @full_sql = CONCAT(@alter_header, @drop_partitions, <span class="string">";"</span>);</div><div class="line"> PREPARE STMT FROM @full_sql;</div><div class="line"> EXECUTE STMT;</div><div class="line"> DEALLOCATE PREPARE STMT;</div><div class="line">  </div><div class="line"> SELECT CONCAT(SCHEMANAME, <span class="string">"."</span>, TABLENAME) AS `table`, @drop_partitions AS `partitions_deleted`;</div><div class="line"> ELSE</div><div class="line"> /*</div><div class="line"> No partitions are being deleted, so <span class="built_in">print</span> out <span class="string">"N/A"</span> (Not applicable) to indicate</div><div class="line"> that no changes were made.</div><div class="line"> */</div><div class="line"> SELECT CONCAT(SCHEMANAME, <span class="string">"."</span>, TABLENAME) AS `table`, <span class="string">"N/A"</span> AS `partitions_deleted`;</div><div class="line"> END IF;</div><div class="line">END$$</div><div class="line">DELIMITER ;</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">DELIMITER $$</div><div class="line">CREATE PROCEDURE `partition_maintenance`(SCHEMA_NAME VARCHAR(32), TABLE_NAME VARCHAR(32), KEEP_DATA_DAYS INT, HOURLY_INTERVAL INT, CREATE_NEXT_INTERVALS INT)</div><div class="line">BEGIN</div><div class="line"> DECLARE OLDER_THAN_PARTITION_DATE VARCHAR(16);</div><div class="line"> DECLARE PARTITION_NAME VARCHAR(16);</div><div class="line"> DECLARE LESS_THAN_TIMESTAMP INT;</div><div class="line"> DECLARE CUR_TIME INT;</div><div class="line">  </div><div class="line"> CALL partition_verify(SCHEMA_NAME, TABLE_NAME, HOURLY_INTERVAL);</div><div class="line"> SET CUR_TIME = UNIX_TIMESTAMP(DATE_FORMAT(NOW(), <span class="string">'%Y-%m-%d 00:00:00'</span>));</div><div class="line">  </div><div class="line"> SET @__interval = 1;</div><div class="line"> create_loop: LOOP</div><div class="line"> IF @__interval &gt; CREATE_NEXT_INTERVALS THEN</div><div class="line"> LEAVE create_loop;</div><div class="line"> END IF;</div><div class="line">  </div><div class="line"> SET LESS_THAN_TIMESTAMP = CUR_TIME + (HOURLY_INTERVAL * @__interval * 3600);</div><div class="line"> SET PARTITION_NAME = FROM_UNIXTIME(CUR_TIME + HOURLY_INTERVAL * (@__interval - 1) * 3600, <span class="string">'p%Y%m%d%H00'</span>);</div><div class="line"> CALL partition_create(SCHEMA_NAME, TABLE_NAME, PARTITION_NAME, LESS_THAN_TIMESTAMP);</div><div class="line"> SET @__interval=@__interval+1;</div><div class="line"> END LOOP;</div><div class="line">  </div><div class="line"> SET OLDER_THAN_PARTITION_DATE=DATE_FORMAT(DATE_SUB(NOW(), INTERVAL KEEP_DATA_DAYS DAY), <span class="string">'%Y%m%d0000'</span>);</div><div class="line"> CALL partition_drop(SCHEMA_NAME, TABLE_NAME, OLDER_THAN_PARTITION_DATE);</div><div class="line">  </div><div class="line">END$$</div><div class="line">DELIMITER ;</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div></pre></td><td class="code"><pre><div class="line">DELIMITER $$</div><div class="line">CREATE PROCEDURE `partition_verify`(SCHEMANAME VARCHAR(64), TABLENAME VARCHAR(64), HOURLYINTERVAL INT(11))</div><div class="line">BEGIN</div><div class="line"> DECLARE PARTITION_NAME VARCHAR(16);</div><div class="line"> DECLARE RETROWS INT(11);</div><div class="line"> DECLARE FUTURE_TIMESTAMP TIMESTAMP;</div><div class="line">  </div><div class="line"> /*</div><div class="line"> * Check <span class="keyword">if</span> any partitions exist <span class="keyword">for</span> the given SCHEMANAME.TABLENAME.</div><div class="line"> */</div><div class="line"> SELECT COUNT(1) INTO RETROWS</div><div class="line"> FROM information_schema.partitions</div><div class="line"> WHERE table_schema = SCHEMANAME AND TABLE_NAME = TABLENAME AND partition_name IS NULL;</div><div class="line">  </div><div class="line"> /*</div><div class="line"> * If partitions <span class="keyword">do</span> not exist, go ahead and partition the table</div><div class="line"> */</div><div class="line"> IF RETROWS = 1 THEN</div><div class="line"> /*</div><div class="line"> * Take the current date at 00:00:00 and add HOURLYINTERVAL to it. This is the timestamp below <span class="built_in">which</span> we will store values.</div><div class="line"> * We begin partitioning based on the beginning of a day. This is because we don<span class="string">'t want to generate a random partition</span></div><div class="line"><span class="string"> * that won'</span>t necessarily fall <span class="keyword">in</span> line with the desired partition naming (ie: <span class="keyword">if</span> the hour interval is 24 hours, we could</div><div class="line"> * end up creating a partition now named <span class="string">"p201403270600"</span> when all other partitions will be like <span class="string">"p201403280000"</span>).</div><div class="line"> */</div><div class="line"> SET FUTURE_TIMESTAMP = TIMESTAMPADD(HOUR, HOURLYINTERVAL, CONCAT(CURDATE(), <span class="string">" "</span>, <span class="string">'00:00:00'</span>));</div><div class="line"> SET PARTITION_NAME = DATE_FORMAT(CURDATE(), <span class="string">'p%Y%m%d%H00'</span>);</div><div class="line">  </div><div class="line"> -- Create the partitioning query</div><div class="line"> SET @__PARTITION_SQL = CONCAT(<span class="string">"ALTER TABLE "</span>, SCHEMANAME, <span class="string">"."</span>, TABLENAME, <span class="string">" PARTITION BY RANGE(`clock`)"</span>);</div><div class="line"> SET @__PARTITION_SQL = CONCAT(@__PARTITION_SQL, <span class="string">"(PARTITION "</span>, PARTITION_NAME, <span class="string">" VALUES LESS THAN ("</span>, UNIX_TIMESTAMP(FUTURE_TIMESTAMP), <span class="string">"));"</span>);</div><div class="line">  </div><div class="line"> -- Run the partitioning query</div><div class="line"> PREPARE STMT FROM @__PARTITION_SQL;</div><div class="line"> EXECUTE STMT;</div><div class="line"> DEALLOCATE PREPARE STMT;</div><div class="line"> END IF;</div><div class="line">END$$</div><div class="line">DELIMITER ;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;上面四个存储过程执行后将可以使用</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">CALL partition_maintenance(<span class="string">'&lt;zabbix_db_name&gt;'</span>, <span class="string">'&lt;table_name&gt;'</span>, &lt;days_to_keep_data&gt;, &lt;hourly_interval&gt;, &lt;num_future_intervals_to_create&gt;)</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;命令对想要分区的表进行表分区了。其中的参数我这里解释一下。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这是举例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">CALL partition_maintenance(zabbix, <span class="string">'history_uint'</span>, 31, 24, 14);</div></pre></td></tr></table></figure>
<ul>
<li>zabbix_db_name：库名</li>
<li>table_name：表名</li>
<li>days_to_keep_data：保存多少天的数据</li>
<li>hourly_interval：每隔多久生成一个分区</li>
<li>num_future_intervals_to_create：本次一共生成多少个分区</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个例子就是history_uint表最多保存31天的数据，每隔24小时生成一个分区，这次一共生成14个分区<br>这里可以将上面四个存储过程保存为一个文件，导入到数据库中，文件我稍后将会放在附件中，这里使用的命令是：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql -uzabbix -pzabbix zabbix&lt;partition_call.sql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后可以将CALL统一调用也做成一个文件，统一调用的内容如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">DELIMITER $$</div><div class="line">CREATE PROCEDURE `partition_maintenance_all`(SCHEMA_NAME VARCHAR(32))</div><div class="line">BEGIN</div><div class="line"> CALL partition_maintenance(SCHEMA_NAME, <span class="string">'history'</span>, 31, 24, 14);</div><div class="line"> CALL partition_maintenance(SCHEMA_NAME, <span class="string">'history_log'</span>, 31, 24, 14);</div><div class="line"> CALL partition_maintenance(SCHEMA_NAME, <span class="string">'history_str'</span>, 31, 24, 14);</div><div class="line"> CALL partition_maintenance(SCHEMA_NAME, <span class="string">'history_text'</span>, 31, 24, 14);</div><div class="line"> CALL partition_maintenance(SCHEMA_NAME, <span class="string">'history_uint'</span>, 31, 24, 14);</div><div class="line"> CALL partition_maintenance(SCHEMA_NAME, <span class="string">'trends'</span>, 180, 24, 14);</div><div class="line"> CALL partition_maintenance(SCHEMA_NAME, <span class="string">'trends_uint'</span>, 180, 24, 14);</div><div class="line">END$$</div><div class="line">DELIMITER ;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;也将该文件导入到数据库中，使用命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql -uzabbix -pzabbix zabbix&lt;partition_all.sql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;好了，到了这里之后就可以使用如下命令执行表分区了：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line">mysql -uzabbix -pzabbix zabbix -e <span class="string">"CALL partition_maintenance_all('zabbix');"</span></div><div class="line">+----------------+--------------------+</div><div class="line">| table | partitions_deleted |</div><div class="line">+----------------+--------------------+</div><div class="line">| zabbix.history | N/A |</div><div class="line">+----------------+--------------------+</div><div class="line">+--------------------+--------------------+</div><div class="line">| table | partitions_deleted |</div><div class="line">+--------------------+--------------------+</div><div class="line">| zabbix.history_log | N/A |</div><div class="line">+--------------------+--------------------+</div><div class="line">+--------------------+--------------------+</div><div class="line">| table | partitions_deleted |</div><div class="line">+--------------------+--------------------+</div><div class="line">| zabbix.history_str | N/A |</div><div class="line">+--------------------+--------------------+</div><div class="line">+---------------------+--------------------+</div><div class="line">| table | partitions_deleted |</div><div class="line">+---------------------+--------------------+</div><div class="line">| zabbix.history_text | N/A |</div><div class="line">+---------------------+--------------------+</div><div class="line">+---------------------+--------------------+</div><div class="line">| table | partitions_deleted |</div><div class="line">+---------------------+--------------------+</div><div class="line">| zabbix.history_uint | N/A |</div><div class="line">+---------------------+--------------------+</div><div class="line">+---------------+--------------------+</div><div class="line">| table | partitions_deleted |</div><div class="line">+---------------+--------------------+</div><div class="line">| zabbix.trends | N/A |</div><div class="line">+---------------+--------------------+</div><div class="line">+--------------------+--------------------+</div><div class="line">| table | partitions_deleted |</div><div class="line">+--------------------+--------------------+</div><div class="line">| zabbix.trends_uint | N/A |</div><div class="line">+--------------------+--------------------+</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;看到如下结果证明所有7张表都进行了表分区，也可以在Mysql的数data目录下看到新生成的表分区文件。（PS:注意，最好是清空history_uint表的数据之后再执行上面这条命令，否则因为这张表数据量太大，转换时间将会好长，清空表中数据的命令为： truncate table history_uint;）</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;好了，这样可以进行表分区了。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将上面这条命令写入到计划任务中如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">crontab -l|tail -1</div><div class="line">01 01 * * * /opt/software/mysql/bin/mysql -uzabbix -pzabbix zabbix -e <span class="string">"CALL partition_maintenance_all('zabbix');"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;每天晚上的1点01执行一次。还有之前写的备份数据库的脚本也需要执行计划任务每天的凌晨0点01执行备份：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">crontab -l|tail -2|head -1</div><div class="line">01 00 * * * /usr/<span class="built_in">local</span>/scripts/Zabbix_MySQLdump_per_table_v2.sh mysqldump</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就大功告成了，之后再体验一下zabbix的web页面看是不是感觉比以前快了？</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/17. zabbix监控进程的CPU和内存占用量/">zabbix监控进程的CPU和内存占用量</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需要对特定服务进行监控，于是，通过编写脚本获取各个进程占用系统资源的信息，从而使用zabbix采集到这些数据进行特定进程的基础监控。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;主要需要监控的程序如下：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>nginx、 redis、 mysql、 tomcat、 sentinel、 mongodb、 openfire、 kafka、 zookeeper、 twemproxy、 mycat</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先，在agent端编写监控脚本，脚本内容如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div></pre></td><td class="code"><pre><div class="line">[zabbix@localhost ~]$ cat zabbix-2.4.4/scripts/processstatus.sh </div><div class="line"><span class="meta">#!/bin/bash</span></div><div class="line"><span class="comment">#license:GPL</span></div><div class="line"><span class="comment">#mail:admin@huxianglin.cn</span></div><div class="line"><span class="comment">#date:2015.06.02</span></div><div class="line"><span class="function"><span class="title">nginx</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"nginx"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">nginxcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"nginx"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">redis</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"redis"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">rediscpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"redis"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mysql</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mysql"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mysqlcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mysql"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">tomcat</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"tomcat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">tomcatcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"tomcat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">sentinel</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"sentinel"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">sentinelcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"sentinel"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mongodb</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mongod"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mongodbcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mongod"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">openfire</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"openfire"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">openfirecpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"openfire"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">kafka</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"kafka"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">kafkacpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"kafka"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">zookeeper</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"zookeeper"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">zookeepercpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"zookeeper"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">twemproxy</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"twemproxy"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">twemproxycpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"twemproxy"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mycat</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mycat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$6&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">mycatcpu</span></span>()&#123;</div><div class="line">ps aux|grep <span class="string">"mycat"</span>|grep -v <span class="string">"grep"</span>|grep -v <span class="string">"processstatus.sh"</span>|awk <span class="string">'&#123;sum+=$3&#125;; END&#123;print sum&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">case</span> <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span></div><div class="line">nginx)</div><div class="line">nginx</div><div class="line">;;</div><div class="line">nginxcpu)</div><div class="line">nginxcpu</div><div class="line">;;</div><div class="line">redis)</div><div class="line">redis</div><div class="line">;;</div><div class="line">rediscpu)</div><div class="line">rediscpu</div><div class="line">;;</div><div class="line">mysql)</div><div class="line">mysql</div><div class="line">;;</div><div class="line">mysqlcpu)</div><div class="line">mysqlcpu</div><div class="line">;;</div><div class="line">tomcat)</div><div class="line">tomcat</div><div class="line">;;</div><div class="line">tomcatcpu)</div><div class="line">tomcatcpu</div><div class="line">;;</div><div class="line">sentinel)</div><div class="line">sentinel</div><div class="line">;;</div><div class="line">sentinelcpu)</div><div class="line">sentinelcpu</div><div class="line">;;</div><div class="line">mongodb)</div><div class="line">mongodb</div><div class="line">;;</div><div class="line">mongodbcpu)</div><div class="line">mongodbcpu</div><div class="line">;;</div><div class="line">openfire)</div><div class="line">openfire</div><div class="line">;;</div><div class="line">openfirecpu)</div><div class="line">openfirecpu</div><div class="line">;;</div><div class="line">kafka)</div><div class="line">kafka</div><div class="line">;;</div><div class="line">kafkacpu)</div><div class="line">kafkacpu</div><div class="line">;;</div><div class="line">zookeeper)</div><div class="line">zookeeper</div><div class="line">;;</div><div class="line">zookeepercpu)</div><div class="line">zookeepercpu</div><div class="line">;;</div><div class="line">twemproxy)</div><div class="line">twemproxy</div><div class="line">;;</div><div class="line">twemproxycpu)</div><div class="line">twemproxycpu</div><div class="line">;;</div><div class="line">mycat)</div><div class="line">mycat</div><div class="line">;;</div><div class="line">mycatcpu)</div><div class="line">mycatcpu</div><div class="line">;;</div><div class="line">*)</div><div class="line"><span class="built_in">echo</span> <span class="string">"Usage: <span class="variable">$0</span> &#123;nginx|nginxcpu|redis|rediscpu|mysql|mysqlcpu|tomcat|tomcatcpu|sentinel|sentinelcpu|mongodb|mongodbcpu|openfire|openfirecpu|kafka|kafkacpu|zookeeper|zookeepercpu|twemproxy|twemproxycpu|mycat|mycatcpu&#125;"</span></div><div class="line">;;</div><div class="line"><span class="keyword">esac</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后修改脚本的权限，使用：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chmod +x processstatus.sh</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在zabbix_agentd.con配置文件中末尾增加如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">[zabbix@localhost ~]$ tail -23 zabbix-2.4.4/etc/zabbix_agentd.conf</div><div class="line"><span class="comment">#monitor process</span></div><div class="line">UserParameter=process.nginx.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh nginx</div><div class="line">UserParameter=process.nginx.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh nginxcpu</div><div class="line">UserParameter=process.redis.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh redis</div><div class="line">UserParameter=process.redis.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh rediscpu</div><div class="line">UserParameter=process.mysql.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mysql</div><div class="line">UserParameter=process.mysql.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mysqlcpu</div><div class="line">UserParameter=process.tomcat.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh tomcat</div><div class="line">UserParameter=process.tomcat.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh tomcatcpu</div><div class="line">UserParameter=process.sentinel.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh sentinel</div><div class="line">UserParameter=process.sentinel.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh sentinelcpu</div><div class="line">UserParameter=process.mongodb.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mongodb</div><div class="line">UserParameter=process.mongodb.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mongodbcpu</div><div class="line">UserParameter=process.openfire.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh openfire</div><div class="line">UserParameter=process.openfire.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh openfirecpu</div><div class="line">UserParameter=process.kafka.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh kafka</div><div class="line">UserParameter=process.kafka.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh kafkacpu</div><div class="line">UserParameter=process.zookeeper.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh zookeeper</div><div class="line">UserParameter=process.zookeeper.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh zookeepercpu</div><div class="line">UserParameter=process.twemproxy.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh twemproxy</div><div class="line">UserParameter=process.twemproxy.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh twemproxycpu</div><div class="line">UserParameter=process.mycat.memory,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mycat</div><div class="line">UserParameter=process.mycat.cpu,/home/zabbix/zabbix-2.4.4/scripts/processstatus.sh mycatcpu</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后重启zabbix_agentd服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">pkill zabbix</div><div class="line">zabbix-2.4.4/sbin/zabbix_agentd</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后在zabbix服务端使用zabbix_get看能否取到相应的数据，像下面这样就是成功获取到了数据。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost zabbix-2.4.4]<span class="comment"># bin/zabbix_get -s 172.16.1.20 -p 10050 -k process.nginx.memory</span></div><div class="line">184876</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后，需要在zabbix中定义模板。模板附件链接在下面。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;zabbix模板下载</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果模板无法下载可以在附件中下载模板</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需要注明的是内存取到的值得单位是KB，所以定义item的时候使用自定义倍数乘以    1000，单位改成Byte，另外CPU占用率的值是带有小数点的一个数，所以在定义item的时    候需要定义值得类型是浮点型，并且该值是占用逻辑单核的CPU占用率，所以需要定义自    定义倍数，我实验中的服务器是2颗CPU，每颗CPU是8核16线程，所以自定义倍数是原来    的基础上除以32，单位改成%就好。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面是做好之后的显示效果：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%E7%9B%91%E6%8E%A7%E8%BF%9B%E7%A8%8B%E7%9A%84CPU%E5%92%8C%E5%86%85%E5%AD%98%E5%8D%A0%E7%94%A8%E9%87%8F/01.jpeg?raw=true" alt=""></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/18. ZABBIX监控H3C设备的CPU和内存使用率/">ZABBIX监控H3C设备的CPU和内存使用率</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;由于最近监控的H3C路由器经常出现死机现象，SNMP获取不到数据，后面检查发现是CPU使用率过高，直接导致无法处理SNMP请求，所以需求来了，怎样通过SNMP监控H3C路由器的CPU和内存使用率？</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;由于CPU和内存的IOD号是H3C厂商没有公布的，所以不好找，在网上百度了一些资料查找H3C网络设备的CPU和内存OID号，这里做个记录，以供以后参考。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;一般H3C网络设备的CPU和内存的IOD号和下面的东西有关。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;H3C cpu 使用率OID：<br>.1.3.6.1.4.1.25506.2.6.1.1.1.1.6.n<br>.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.6.n<br>.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.6.n    </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;H3C 内存使用率OID：<br>.1.3.6.1.4.1.25506.2.6.1.1.1.1.8.n<br>.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.8.n<br>.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.8.n    </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先，在设备上面使用命令display mib-style查看显示的结果，如果显示的是?      new，则需要使用hh3c-entity-ext.mib文件中的hh3cEntityExtCpuUsage节点，该节点的    信息是对象OID .1.3.6.1.4.1.25506.2.6.1.1.1.1.6.n</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果显示的是? compatible，则需要使用h3c-entity-ext.mib文件中的    h3cEntityExtCpuUsage节点，该节点的信息是对象OID .1.3.6.1.4.1.2011.10.2.6.1.1.1.1.6.n</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;至于n的值不同设备不一样，可以使用snmp获取.1.3.6.1.4.1.25506.2.6.1.1.1.1.6的值，其中有一大串输出，其他输出都是0，只有某一个输出是非0的，那个就是CPU的OID号，例如我这的H3C路由器的CPUOID号就是.1.3.6.1.4.1.25506.2.6.1.1.1.1.6.3有非零的值，那么说明.1.3.6.1.4.1.25506.2.6.1.1.1.1.6.3就是CPU的OID号。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内存的OID号判断也是如此，确定了OID号，那么使用zabbix通过snmp监控内存和CPU那就轻而易举了。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/16. zabbix监控php状态/">zabbix监控php状态</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;通过nginx调用php-fpm来查询php的状态信息</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先，在php的配置文件中添加一行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim /usr/<span class="built_in">local</span>/php/etc/php-fpm.conf</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pm.status_path = /phpfpmstatus</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存后重启php-fpm</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在nginx配置文件中添加代码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">server </div><div class="line">&#123;  </div><div class="line">	listen localhost:80;  </div><div class="line">	server_name localhost;</div><div class="line">location /nginxstatus &#123;  </div><div class="line">	stub_status on;  </div><div class="line">	access_log off;  </div><div class="line">	allow 127.0.0.1;</div><div class="line">	allow 10.6.0.187;   </div><div class="line">	deny all;  </div><div class="line">	&#125;</div><div class="line">location ~ ^/(phpfpmstatus)$ &#123;</div><div class="line">        include fastcgi_params;</div><div class="line">        fastcgi_pass unix:/tmp/php-fcgi.sock;</div><div class="line">        fastcgi_param SCRIPT_FILENAME /usr/<span class="built_in">local</span>/nginx/html<span class="variable">$fastcgi_script_name</span>;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存后重启nginx</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后使用<code>curl -s http://localhost/phpfpmstatus</code>查看是否能够获取到php状态信息</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后，在zabbix的脚本目录里面编辑执行脚本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/bin/bash</span></div><div class="line"></div><div class="line"><span class="comment">#monitor php-fpm status from zabbix</span></div><div class="line"><span class="comment">#lincense:GPL</span></div><div class="line"><span class="comment">#mail:admin@huxianglin.cn</span></div><div class="line"><span class="comment">#date:2015.04.15</span></div><div class="line"></div><div class="line"><span class="built_in">source</span> /etc/bashrc &gt;/dev/null 2&gt;&amp;1</div><div class="line"><span class="built_in">source</span> /etc/profile &gt;/dev/null 2&gt;&amp;1</div><div class="line"></div><div class="line">LOG=/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpfpmstatus.log</div><div class="line">curl -s http://localhost/phpfpmstatus &gt;<span class="variable">$LOG</span></div><div class="line"></div><div class="line"><span class="function"><span class="title">pool</span></span>()&#123;</div><div class="line">	awk <span class="string">'/pool/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">process_manager</span></span>()&#123;</div><div class="line">	awk <span class="string">'/process manager/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">start_since</span></span>()&#123;</div><div class="line">	awk <span class="string">'/start since:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">accepted_conn</span></span>()&#123;</div><div class="line">        awk <span class="string">'/accepted conn:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"><span class="function"><span class="title">listen_queue</span></span>()&#123;</div><div class="line">        awk <span class="string">'/^(listen queue:)/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">max_listen_queue</span></span>()&#123;</div><div class="line">        awk <span class="string">'/max listen queue:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">listen_queue_len</span></span>()&#123;</div><div class="line">        awk <span class="string">'/listen queue len:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">idle_processes</span></span>()&#123;</div><div class="line">        awk <span class="string">'/idle processes:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">active_processes</span></span>()&#123;</div><div class="line">        awk <span class="string">'/^(active processes:)/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">total_processes</span></span>()&#123;</div><div class="line">        awk <span class="string">'/total processes:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">max_active_processes</span></span>()&#123;</div><div class="line">        awk <span class="string">'/max active processes:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="title">max_children_reached</span></span>()&#123;</div><div class="line">        awk <span class="string">'/max children reached:/ &#123;print $NF&#125;'</span> <span class="variable">$LOG</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">case</span> <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span></div><div class="line">pool)</div><div class="line">	pool</div><div class="line">	;;</div><div class="line">process_manager)</div><div class="line">	process_manager</div><div class="line">	;;</div><div class="line">start_since)</div><div class="line">	start_since</div><div class="line">	;;</div><div class="line">accepted_conn)</div><div class="line">	accepted_conn</div><div class="line">	;;</div><div class="line">listen_queue)</div><div class="line">	listen_queue</div><div class="line">	;;</div><div class="line">max_listen_queue)</div><div class="line">	max_listen_queue</div><div class="line">	;;</div><div class="line">listen_queue_len)</div><div class="line">	listen_queue_len</div><div class="line">	;;</div><div class="line">idle_processes)</div><div class="line">	idle_processes</div><div class="line">	;;</div><div class="line">active_processes)</div><div class="line">	active_processes</div><div class="line">	;;</div><div class="line">total_processes)</div><div class="line">	total_processes</div><div class="line">	;;</div><div class="line">max_active_processes)</div><div class="line">	max_active_processes</div><div class="line">	;;</div><div class="line">max_children_reached)</div><div class="line">	max_children_reached</div><div class="line">	;;</div><div class="line">*)</div><div class="line"><span class="built_in">echo</span> <span class="string">"Usage: <span class="variable">$0</span> &#123;pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached&#125;"</span></div><div class="line"><span class="keyword">esac</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存后退出，修改权限为</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">-rwxr-xr-x 1 zabbix zabbix 1770 4月  15 14:50 phpstatus.sh</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后编辑zabbix_agentd.conf文件，在最后添加上下面这段代码，并重启zabbix_agentd服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#to monitor php-fpmstatus</span></div><div class="line">UserParameter=phpfpm.status.pool,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh pool</div><div class="line">UserParameter=phpfpm.status.process.manager,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh process_manager</div><div class="line">UserParameter=phpfpm.status.start.since,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh start_since</div><div class="line">UserParameter=phpfpm.status.accepted.conn,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh accepted_conn</div><div class="line">UserParameter=phpfpm.status.listen.queue,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh listen_queue</div><div class="line">UserParameter=phpfpm.status.max.listen.queue,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh max_listen_queue</div><div class="line">UserParameter=phpfpm.status.listen.queue.len,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh listen_queue_len</div><div class="line">UserParameter=phpfpm.status.idle.processes,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh idle_processes</div><div class="line">UserParameter=phpfpm.status.active.processes,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh active_processes</div><div class="line">UserParameter=phpfpm.status.total.processes,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh total_processes</div><div class="line">UserParameter=phpfpm.status.max.active.processes,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh max_active_processes</div><div class="line">UserParameter=phpfpm.status.max.children.reached,/usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/phpstatus.sh max_children_reached</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后就可以在web端配置item监控php状态了</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%E7%9B%91%E6%8E%A7php%E7%8A%B6%E6%80%81/01.jpeg?raw=true" alt=""></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/15. zabbix监控nginx状态/">zabbix监控nginx状态</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先，在nginx的配置文件中添加如下一段代码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">server </div><div class="line">&#123; </div><div class="line">    listen localhost:80; </div><div class="line">    server_name localhost;</div><div class="line">    location /nginxstatus &#123; </div><div class="line">    stub_status on; </div><div class="line">    access_log off; </div><div class="line">    allow 127.0.0.1;</div><div class="line">    allow 192.168.1.165; </div><div class="line">    deny all; </div><div class="line">    &#125; </div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存之后重启nginx</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在zabbix脚本目录下创建脚本监控zabbix状态</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cat nginx_status.sh</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/bin/bash </span></div><div class="line"><span class="comment"># Script to fetch nginx statuses for tribily monitoring systems </span></div><div class="line"><span class="comment"># Author: admin@huxianglin.cn </span></div><div class="line"><span class="comment"># License: GPLv2 </span></div><div class="line"><span class="comment"># Set Variables </span></div><div class="line"><span class="comment"># Functions to return nginx stats </span></div><div class="line"><span class="keyword">function</span> active &#123;</div><div class="line">curl -s <span class="string">"http://localhost/nginx_status"</span>| awk <span class="string">'/Active/&#123;print $3&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">function</span> reading &#123;</div><div class="line">curl -s <span class="string">"http://localhost/nginx_status"</span>| awk <span class="string">'/Reading/&#123;print $2&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">function</span> writing &#123;</div><div class="line">curl -s <span class="string">"http://localhost/nginx_status"</span>| awk <span class="string">'/Writing/&#123;print $4&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">function</span> waiting &#123;</div><div class="line">curl -s <span class="string">"http://localhost/nginx_status"</span>| awk <span class="string">'/Waiting/&#123;print $6&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">function</span> accepts &#123;</div><div class="line">curl -s <span class="string">"http://localhost/nginx_status"</span>| awk NR==3| awk <span class="string">'&#123;print $1&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">function</span> handled &#123;</div><div class="line">curl -s <span class="string">"http://localhost/nginx_status"</span>| awk NR==3| awk <span class="string">'&#123;print $2&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="keyword">function</span> requests &#123;</div><div class="line">curl -s <span class="string">"http://localhost/nginx_status"</span>| awk NR==3| awk <span class="string">'&#123;print $3&#125;'</span></div><div class="line">&#125;</div><div class="line"><span class="comment"># Run the requested function </span></div><div class="line"><span class="keyword">case</span> <span class="string">"<span class="variable">$1</span>"</span> <span class="keyword">in</span></div><div class="line">active)</div><div class="line">active</div><div class="line">;;</div><div class="line">reading)</div><div class="line">reading</div><div class="line">;;</div><div class="line">writing)</div><div class="line">writing</div><div class="line">;;</div><div class="line">waiting)</div><div class="line">waiting</div><div class="line">;;</div><div class="line">accepts)</div><div class="line">accepts</div><div class="line">;;</div><div class="line">handled)</div><div class="line">handled</div><div class="line">;;</div><div class="line">requests)</div><div class="line">requests</div><div class="line">;;</div><div class="line">*)</div><div class="line"><span class="built_in">echo</span> <span class="string">"Usage: <span class="variable">$0</span> &#123;nginx_site_dicovery&#125;"</span></div><div class="line"><span class="built_in">echo</span> <span class="string">"Usage: <span class="variable">$0</span> &#123;active [host] | reading [host] | writing [host] | waiting [host] | accepts [host] | handled [host] | requests [host]&#125;"</span></div><div class="line"><span class="keyword">esac</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后修改该文件的属主和属组为zabbix，并且具有执行权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">chown zabbix.zabbix /usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/nginx_status.sh</div><div class="line">chmod 755 /usr/<span class="built_in">local</span>/zabbix-2.4.4/scripts/nginx_status.sh</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后在zabbix_agentd.conf配置文件中添加如下代码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#monitor nginx</span></div><div class="line">UserParameter=nginx.accepts,/usr/<span class="built_in">local</span>/etc/nginx_status.sh accepts</div><div class="line">UserParameter=nginx.handled,/usr/<span class="built_in">local</span>/etc/nginx_status.sh handled</div><div class="line">UserParameter=nginx.requests,/usr/<span class="built_in">local</span>/etc/nginx_status.sh requests</div><div class="line">UserParameter=nginx.connections.active,/usr/<span class="built_in">local</span>/etc/nginx_status.sh active</div><div class="line">UserParameter=nginx.connections.reading,/usr/<span class="built_in">local</span>/etc/nginx_status.sh reading</div><div class="line">UserParameter=nginx.connections.writing,/usr/<span class="built_in">local</span>/etc/nginx_status.sh writing</div><div class="line">UserParameter=nginx.connections.waiting,/usr/<span class="built_in">local</span>/etc/nginx_status.sh waiting</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这段代码可以视自己目录情况而改变</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建好了之后就可以在web页面配置item监控项了</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/14. zabbix监控mysql数据库状态/">zabbix监控mysql数据库状态</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Zabbix自己提供的模板可以监控mysql slow queries,mysqlversion,uptime,alive等。</p>
<ol>
<li><p>Zabbix官方提供的监控mysql的模板Template AppMySQL,可以看到相关的Items和key。</p>
</li>
<li><p>把该模板Template App MySQL Link到相关的主机上面,发现Item的Status是不可用的，因为key的值是通过Mysql用户查看”showglobal status”信息或者用mysqladmin命令查看status或extended-status的信息而取的值。</p>
</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show global status; </div><div class="line">mysql&gt; show status;</div></pre></td></tr></table></figure>
<ol>
<li>结合官方提供的key编写Shell脚本，从数据库中取出Items的key的值。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/bin/sh</span></div><div class="line"><span class="comment">#Create by huxianglin 2015.04.14</span></div><div class="line">MYSQL_SOCK=<span class="string">"/tmp/mysql.sock"</span></div><div class="line">MYSQL_PWD=xxxxxx</div><div class="line"><span class="built_in">source</span> /etc/profile.d/mysqld.sh</div><div class="line">ARGS=1</div><div class="line"><span class="keyword">if</span> [ <span class="variable">$#</span> -ne <span class="string">"<span class="variable">$ARGS</span>"</span> ];<span class="keyword">then</span></div><div class="line"><span class="built_in">echo</span> <span class="string">"Please input onearguement:"</span></div><div class="line"><span class="keyword">fi</span></div><div class="line"><span class="keyword">case</span> <span class="variable">$1</span> <span class="keyword">in</span></div><div class="line">Uptime)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> status|cut -f2 -d<span class="string">":"</span>|cut -f1 -d<span class="string">"T"</span>`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Com_update)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Com_update"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Slow_queries)</div><div class="line">result=`mysqladmin -uroot -p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> status |cut -f5 -d<span class="string">":"</span>|cut -f1 -d<span class="string">"O"</span>`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Com_select)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Com_select"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Com_rollback)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Com_rollback"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Questions)</div><div class="line">result=`mysqladmin -uroot -p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> status|cut -f4 -d<span class="string">":"</span>|cut -f1 -d<span class="string">"S"</span>`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Com_insert)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Com_insert"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Com_delete)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Com_delete"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Com_commit)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Com_commit"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Bytes_sent)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Bytes_sent"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Bytes_received)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Bytes_received"</span> |cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line">Com_begin)</div><div class="line">result=`mysqladmin -uroot-p<span class="variable">$&#123;MYSQL_PWD&#125;</span> -S <span class="variable">$MYSQL_SOCK</span> extended-status |grep -w <span class="string">"Com_begin"</span>|cut -d<span class="string">"|"</span> -f3`</div><div class="line"><span class="built_in">echo</span> <span class="variable">$result</span></div><div class="line">;;</div><div class="line"></div><div class="line">*)</div><div class="line"><span class="built_in">echo</span><span class="string">"Usage:<span class="variable">$0</span>(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions)"</span></div><div class="line">;;</div><div class="line"><span class="keyword">esac</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>修改权限chmod 755 /etc/zabbix-2.4.4/scripts/checkmysqlperformance.sh</strong></p>
<ol>
<li>在Zabbix_agentd.conf里面添加UserParameter，格式如下，对于Zabbix来说，脚本其实就是一个插件。</li>
</ol>
<ul>
<li>UserParameter=mysql.version,mysql -V </li>
<li>UserParameter=mysql.ping,mysqladmin -uroot -pxxxxxx -S /tmp/mysql.sock ping | grep -c alive </li>
<li>UserParameter=mysql.status[*],/etc/zabbix-2.4.4/scripts/checkmysqlperformance.sh $1 $2 </li>
<li>重启agentd服务器，然后在zabbix server中添加模板Template AppMySQL。 </li>
<li>在zabbix前端可以实时查看SQL语句每秒钟的操作次数。</li>
</ul>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%E7%9B%91%E6%8E%A7mysql%E6%95%B0%E6%8D%AE%E5%BA%93%E7%8A%B6%E6%80%81/01.jpeg?raw=true" alt=""></figure></p>
<ul>
<li>在zabbix前端可以实时查看mysql发送接收的字节数。其中bytes received表示从所有客户端接收到的字节数，bytes sent表示发送给所有客户端的字节数。</li>
</ul>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/zabbix%E7%9B%91%E6%8E%A7mysql%E6%95%B0%E6%8D%AE%E5%BA%93%E7%8A%B6%E6%80%81/02.jpeg?raw=true" alt=""></figure></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;把该脚本放到要监控的服务器上面（Modifymysql user and password），修改UserParameter的参数并重启agentd,Link官方提供的Template App MySQL模板即可。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这里是测试环境用root账号，线上服务器安全期间可以给mysql用户授权readonly权限。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;根据实际的需求，除了监控上述监控项之外，还可以监控mysqlprocesslist,Innodb等。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/13. zabbix监控mongodb/">zabbix监控mongodb</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mongodb的监控，下面是部署过程：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第一步，先在zabbix_agentd.conf中追加下面的内容，主要是调用mongo这个工具通过db.serverStatus()函数获取mongodb的状态，这里需要注意的是连接的IP和端口不能配置错误，最好是要检查一下mongodb的配置文件里面的IP和端口是否一致：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#monitor mongodb</span></div><div class="line">UserParameter=mongo.service,ps -ef | grep mongo |grep -v grep |wc -l</div><div class="line">UserParameter=mongo.mem_resident,<span class="built_in">echo</span> <span class="string">"db.serverStatus().mem"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep resident | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f 1| cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.mem_virtual,<span class="built_in">echo</span> <span class="string">"db.serverStatus().mem"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep virtual | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f 1| cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.mem_mapped,<span class="built_in">echo</span> <span class="string">"db.serverStatus().mem"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep <span class="string">'\bmapped\b'</span> | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f 1| cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.network[*],<span class="built_in">echo</span> <span class="string">"db.serverStatus().network"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep <span class="variable">$1</span> | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.index[*],<span class="built_in">echo</span> <span class="string">"db.serverStatus().indexCounters"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep <span class="variable">$1</span>| cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.connection_current,<span class="built_in">echo</span> <span class="string">"db.serverStatus().connections"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep current|cut -d <span class="string">":"</span> -f 2|cut -d <span class="string">","</span> -f 1|cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.connection_available,<span class="built_in">echo</span> <span class="string">"db.serverStatus().connections"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep current| cut -d <span class="string">":"</span> -f 3|cut -d <span class="string">","</span> -f 1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.opcounters[*],<span class="built_in">echo</span> <span class="string">"db.serverStatus().opcounters"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep <span class="variable">$1</span>|cut -d <span class="string">":"</span> -f 2|cut -d <span class="string">","</span> -f 1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.rpstatus,<span class="built_in">echo</span> <span class="string">"rs.status()"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep myState| cut -d <span class="string">":"</span> -f 2| cut -d <span class="string">","</span> -f 1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.queue_write,<span class="built_in">echo</span> <span class="string">"db.serverStatus().globalLock.currentQueue.writers"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.queue_reader,<span class="built_in">echo</span> <span class="string">"db.serverStatus().globalLock.currentQueue.readers"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.backgroundFlush,<span class="built_in">echo</span> <span class="string">"db.serverStatus().backgroundFlushing.last_ms"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.curosor_Totalopen,<span class="built_in">echo</span> <span class="string">"db.serverStatus().cursors.totalOpen"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.curospr_timedOu,<span class="built_in">echo</span> <span class="string">"db.serverStatus().cursors.timedOut"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.pagefaults,<span class="built_in">echo</span> <span class="string">"db.serverStatus().extra_info.page_faults"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.oplog_storetime,<span class="built_in">echo</span> <span class="string">"db.printReplicationInfo()"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 4p|cut -d <span class="string">"("</span> -f 2|cut -d <span class="string">"h"</span> -f 1</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;追加完成后重启zabbix_agentd然后在zabbix_server端使用zabbix_get尝试是否能够获取到数据，如果能获取到数据说明客户端已经配置好了，接下来配置服务端，将下面提供的模板导入，然后添加相应主机到模版中就行了。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/12. zabbix2.2图形中有乱码（方框）的问题/">zabbix2.2图形中有乱码（方框）的问题</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个是字体的问题，解决办法如下：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;yum 安装的zabbix 字体并不是在   /usr/share/zabbix/fonts下而是在/usr/share/zabbix/fonts/dejavu 下，具体配置可以通过查看配置文件：/usr/share/zabbix/include/defines.inc.php</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需要搞一个中文字体放到这里来，虽然这个目录下有个 DejaVuSans.ttf 但是不管用，从windows上的 C:\windows\fonts\ 目录下拷贝文件 simfang.ttf 到 /usr/share/zabbix/fonts/dejavu 目录下，然后修改名字</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mv DejaVuSans.ttf DejaVuSans.ttf.bak </div><div class="line">mv simfang.ttf DejaVuSans.ttf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就可以了。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Zabbix/11. zabbix agent 类型所有key/">zabbix agent 类型所有key</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;zabbix服务器端通过与zabbix agent通信来获取客户端服务器的数据，agent分为两个版本，在配置主机我们可以看到一个是agent，另一个是agent（active）。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;agent：zabbix server向zabbix agent讨要数据。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;agent（active）：zabbix agent提交数据给zabbix server。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;监控项keys列表</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以下表格是zabbix agent所支持的所有key列表，添加一向监控的时候，首先想到的应该是zabbix agent是否已经有相关的key存在，而不是自己去写脚本来获取key。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>agent.hostname</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回被监控端名称(字符串)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>agent.ping</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测被监控端是否存活(1:运行中 其他:未运行)-使用函数 nodata()检测客户端是否正在运行</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>agent.version</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;zabbix agent版本字符串</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>kernel.maxfiles</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;系统支持最大的open files整数</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>kernel.maxproc</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;系统支持最大的进程数量整数</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>log[file,<regexp>,<encoding>,<maxlines>,<mode>,<output>]</output></mode></maxlines></encoding></regexp></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;监控日志文件<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file - 文件详细路径<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;regexp - 正则<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;encoding - 编码<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;maxlines - zabbix agent向server或者proxy发送最大的行数。这个参数覆盖配置文件zabbxi_agentd.conf中的’MaxLinesPerSecond’<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - 可选值:all (默认), skip (跳过处理老数据).mode参数从2.0版本开始支持<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;output - 可选项，输出格式模板.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例: log[/var/log/syslog] log[/var/log/syslog,error] log[/home/zabbix/logs/logfile,,,100]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>logrt[file_pattern,<regexp>,<encoding>,<maxlines>,<mode>,<output>]</output></mode></maxlines></encoding></regexp></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Monitoring of log file with log rotation support.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file_pattern - 文件绝对路径    </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.dns[<ip>,zone,<type>,<timeout>,<count>]</count></timeout></type></ip></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测DNS服务是否开启0 – DNS挂了  1 - DNS运行中<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ip - DNS服务器的ip地址(留空表示使用本地DNS, ignored onWindows)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;zone - 需要测试的域名<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - 记录类型 (默认为 SOA),type可选值:  ANY, A, NS, CNAME, MB, MG, MR, PTR, MD, MF, MX, SOA, NULL, WKS (除了windows), HINFO, MINFO, TXT, SRV SRV<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;timeout (ignored on Windows) – 超时时间(默认1秒)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;count (ignored on Windows) – 重试次数 (默认值2)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: net.dns[8.8.8.8,zabbix.com,MX,2,1]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.dns.record[<ip>,zone,<type>,<timeout>,<count>]</count></timeout></type></ip></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行一个DNS查询获取DNS查询数据.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ip - DNS服务器的ip地址(留空表示使用本地DNS, ignored on Windows)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;zone - 需要测试的域名<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - 记录类型 (默认SOA,可选值同net.dns)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;timeout (ignored on Windows) – 超时时间(默认1秒)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;count (ignored on Windows) – 重试次数 (默认值2)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: net.dns.record[8.8.8.8,ttlsa.com,MX,2,1]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.if.collisions[if]</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Out-of-window collision.Number of collisions. Integer.if - 网卡</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.if.discovery</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列出网卡.通常用于低级别的discovery.JSON对象</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.if.in[if,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;网卡入口流量整数.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if - 网卡名称<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - 可用值: bytes - 字节数 (默认)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;packets - 包数量<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;errors - 错误数量<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dropped - 丢包数量<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例keys: net.if.in[eth0,errors] net.if.in[eth0]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.if.out[if,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;网卡出口流量（参数参见net.if.in）</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.if.total[if,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;网卡进/出流量的总和（参数参见net.if.in）</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.tcp.listen[port]</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测端口是否开启0 – （not listen） 1 –  in LISTEN stateport<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例: net.tcp.listen[80]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.tcp.port[<ip>,port]</ip></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;是否可以连接到指定的TCP端口0 – cannot connect 1 – can connect<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;   ip - IP地址(默认是 127.0.0.1)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;   port - 端口<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例: net.tcp.port[,80] 检测web服务器端口是否运行中</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.tcp.service[service,<ip>,<port>]</port></ip></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测服务是否开启，并且端口可用0 – 服务挂了 1 – 服务运行中<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;    service - 如下:ssh, ntp, ldap, smtp, ftp, http, pop, nntp,imap, tcp, https, telnet<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;    ip - IP地址 (默认127.0.0.1)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;    port - 端口 (默认情况为标准端口号)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: net.tcp.service[ftp,,45]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>net.tcp.service.perf[service,<ip>,<port>]</port></ip></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测服务器性能0 – 服务挂了; seconds – 链接到服务器端口消耗的时间<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;service - 如下:ssh, ntp, ldap, smtp, ftp, http, pop, nntp,imap, tcp, https, telnet<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ip - IP地址 (默认127.0.0.1)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;port - 端口 (默认情况为标准端口号)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: net.tcp.service.perf[ssh]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;net.udp.listen[port]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>proc.mem[<name>,<user>,<mode>,<cmdline>]</cmdline></mode></user></name></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用户进程消耗的内存内存使用量 (字节单位).<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;name - 进程名 (默认值 “all processes”)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;user - 用户名 (默认值“all users”)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - 可选值: avg, max, min, sum (默认)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cmdline - 命令行过滤(正则表达时)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例keys: proc.mem[,root] – root的进程消耗了多少内存<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;    proc.mem[zabbix_server,zabbix] – zabbix用户运行的zabbix_server使用了多少内存<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;    proc.mem[,oracle,max,oracleZABBIX]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>proc.num[<name>,<user>,<state>,<cmdline>]</cmdline></state></user></name></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;某用户某些状态的进程的数量进程数量<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;name - 进程名称 (默认“all processes”)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;user - 用户名 (默认 “all users”)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;state - 可用值: all (默认), run,sleep, zomb<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cmdline - 命令行过滤(正则表达时)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例keys: proc.num[,mysql] – MySQL用户运行的进程数量<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.num[apache2,www-data] – www-data运行了多少个apache2进程<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;proc.num[,oracle,sleep,oracleZABBIX]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;备注：Windows系统只支持name和user两个参数</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>sensor[device,sensor,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;读取硬件传感器<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;device - 设备名称<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;sensor - 传感器名称<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - 可选值:avg, max, min<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: sensor[w83781d-i2c-0-2d,temp1] Prior to Zabbix 1.8.4, the sensor[temp1] format was used. On Linux 2.6+, 读取/sys/class/hwmon. On OpenBSD, 读取hw.sensors MIB.示例keys: sensor[cpu0,temp0] – CPU0的温度 sensor[cpu[0-2]$,temp,avg] – cpu平均温度Zabbix 1.8.4开始支持OpenBSD</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.boottime</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;系统启动的时间戳整数.unix时间戳</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.cpu.intr</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;设备中断整数</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.cpu.load[<cpu>,<mode>]</mode></cpu></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CPU负载浮点数<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cpu - 可用值: all (默认), percpu (所有在线cpu的负载)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - 可用值:avg1 (1分钟 默认值), avg5(5分钟平均), avg15 (15分钟平均值)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例key: system.cpu.load[,avg5]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.cpu.num[<type>]</type></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CPU数量处理器个数type - 可用值: online (默认值), max范例: system.cpu.num</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.cpu.switches</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;上下文交换交换次数老命名方式: system[switches]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.cpu.util[<cpu>,<type>,<mode>]</mode></type></cpu></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CPU利用率百分比<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cpu - cpu数量 (默认是所有cpu)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - 可用值: idle, nice, user (默认), system (windows系统默认值）, iowait, interrupt, softirq,steal<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - 可用值: avg1 (一分钟平均，默认值), avg5(5分钟平均, avg15 (15分钟平均值)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例key: system.cpu.util[0,user,avg5]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.hostname[<type>]</type></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回主机名字符串<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type (仅用于windows系统) – 可用值: netbios(默认) or host</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.hw.chassis[<info>]</info></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回机架信息字符串<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;info - full (默认), model, serial, type 或vendor<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: system.hw.chassis<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Hewlett-Packard HP Pro 3010 Small Form Factor PC CZXXXXXXXX Desktop]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;备注：要root权限，因为这些信息是从内存中读取的。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.hw.cpu[<cpu>,<info>]</info></cpu></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回CPU信息字符/数字<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cpu - cpu数量或者all (默认)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;info - full (默认), curfreq, maxfreq, model 或者vendor<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: system.hw.cpu[0,vendor] AuthenticAMD 从/proc/cpuinfo、/sys/devices/system/cpu/[cpunum]/cpufreq/cpuinfo_max_freq获取信息. 如果指定了CPU数量和 curfreq或者maxfreq, 将会返回数值(Hz).</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.hw.devices[<type>]</type></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列出PCI或者USB文本值<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - pci (默认) or usb<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例: system.hw.devices[pci] 00:00.0 Host bridge: Advanced Micro Devices [AMD] RS780 Host Bridge [..] 返回lspci或者lsusb (不带参数)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.hw.macaddr[<interface>,<format>]</format></interface></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列出MAC地址字符串<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;interface - all (默认) 或者正则表达式<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;format - full (默认) 、short<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例: system.hw.macaddr[“eth0$”,full] [eth0] 00:11:22:33:44:55 列出指定接口mac地址 如果format指定为short，MAC地址相同的将会被忽略掉</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.localtime[<type>]</type></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;系统时间.数字或者字符串</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.run[command,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在制定的主机上运行命令文本<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;command - 命令<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - wait (默认值, 执行超时时间), nowait (不等待)最大可用返回512KB数据，包含空白数据。 命令输出数据必须是文本<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: system.run[ls -l /] – 列出/的文件和目录.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Note: 启用这个方法, agent配置文件必须配置 EnableRemoteCommands=1选项</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.stat[resource,<type>]</type></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;虚拟内存状态数字ent</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.sw.arch</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回软件信息字符串<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例: system.sw.arch i686</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.sw.os[<info>]</info></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回系统信息字符串<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;info - full (default), short ,name<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例: system.sw.os[short] Ubuntu 2.6.35-28.50-generic 2.6.35.11<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;信息来自如下文件：<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/proc/version [short]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/proc/version_signature [name]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/etc/issue.net</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.sw.packages[<package>,<manager>,<format>]</format></manager></package></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;已安装软件列表文本值<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;package - all (默认)或者正则表达式<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;manager - all (默认) or a package manager<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;format - full (默认) ，short<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;范例: system.sw.packages[mini,dpkg,short]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.swap.in[<device>,<type>]</type></device></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;交换分区IN（磁盘交换到内存）数字<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;device - 交换分区设备 (默认all)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - 可选值: count (swapins数量), sectors(sectors swapped in), pages (pages swapped in).<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: system.swap.in[,pages]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;数据采集自: Linux 2.4: /proc/swaps, /proc/partitions, /proc/stat<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux 2.6: /proc/swaps, /proc/diskstats, /proc/vmstat</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.swap.out[<device>,<type>]</type></device></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Swap out (f内存到磁盘) .数字<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;device - swap设备 (默认all)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - count (number of swapouts), sectors(sectors swapped out), pages (pages swapped out).<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: system.swap.out[,pages]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;数据采集自: Linux 2.4: /proc/swaps, /proc/partitions, /proc/stat<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux 2.6: /proc/swaps, /proc/diskstats, /proc/vmstat</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.swap.size[<device>,<type>]</type></device></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;交换分区大小字节或者百分比<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;device - 交换分区 (默认值 all)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - free (free swap space, default), pfree (free swap space, in percent), pused (used swap space, in percent), total (total swap space), used (used swap space)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例 system.swap.size[,pfree] – 空闲swap百分比</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.uname</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;返回主机相信信息.字符串</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.uptime</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;系统运行时长(秒)多少秒使用s/uptime来获取</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>system.users.num</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;登陆用户数量多少用户agent使用who命令获取</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.dev.read[<device>,<type>,<mode>]</mode></type></device></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;磁盘读取状态整数，浮点数（如果type为如下）<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;device - 磁盘设备 (默认值 “all”)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - 可选值:sectors, operations, bytes, sps, ops, bps(必须指定, 不同操作系统下不同).  sps, ops, bps stand for: sectors, operations, bytes per second, respectively<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - 可选值: avg1, avg5, avg15.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;备注: 只有type为sps, ops, bps的时候，第三个参数才被支持。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;不同操作系统的TYPE参数： FreeBSD – bps Linux – sps OpenBSD – operations Solaris – bytes<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;示例key: vfs.dev.read[,operations]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.dev.write[<device>,<type>,<mode>]</mode></type></device></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;磁盘写入状态整数，<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;device - 磁盘设备 (默认 all)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;type - sectors, operations, bytes, sps, ops, bps<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - one of avg1 (default),avg5 , avg15.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;example: vfs.dev.write[,operations] Old naming: io</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.cksum[file]</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;计算文件校验 UNIX cksum.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file - 文件完整路径</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.contents[file,<encoding>]</encoding></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;获取文本内容若为空，只返回 LF/CR characters.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file - 文件完整路径<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: vfs.file.contents[/etc/passwd] 文件不可以超过64KB.  </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.exists[file]</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测文件是否存在1 – 存在 0 – 不存在<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file - 文件完整路径</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.md5sum[file]</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件MD5校验码文件MD5哈希值<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file - 完整路径</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.regexp[file,regexp,<encoding>,<start line="">,<end line="">,<output>]</output></end></start></encoding></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件中搜索字符串包含字符串的行，或者为空<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file - 文件完整路径<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;regexp - GNU正则表达式<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;encoding - 编码<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;start line - 从哪一行开始，默认第一行<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;end line - 从哪一行结束，默认最后一行<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如: vfs.file.regexp[/etc/passwd,zabbix]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;vfs.file.regexp[/path/to/some/file,”([0-9]+)$”,,3,5,\1]<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;vfs.file.regexp[/etc/passwd,^zabbix:.:([0-9]+),,,,\1]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.regmatch[file,regexp,<encoding>,<start line="">,<end line="">]</end></start></encoding></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件中搜索字符串0 – 未找到 1 – 找到<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;file - 文件完整路径<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;regexp - GNU 正则表达式<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;encoding - 编码<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;start line - 哪行开始，默认第一行<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;end line - 哪行结束，默认最后一行<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: vfs.file.regmatch[/var/log/app.log,error]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.size[file]</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件大小字节fzabbix必须有可读此文件的权限</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.file.time[file,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;文件时间信息Unix 时间戳.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode -  modify (默认, 修改时间), access – 最后访问时间, change – 最后改变时间<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: vfs.file.time[/etc/passwd,modify] 备注：文件大小有限制</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.fs.discovery</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;列出挂载的文件系统 用于lld.JSON对象</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.fs.inode[fs,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;inodes数量数字<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fs - 文件系统<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - total (默认), free, used, pfree (空闲百分比), pused (使用百分比)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: vfs.fs.inode[/,pfree]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vfs.fs.size[fs,<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;磁盘空间，返回本地文件系统的使用量字节<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;fs - 文件系统<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode -  total (默认), free, used, pfree (空闲百分比), pused (使用百分比).<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;例如: vfs.fs.size[/tmp,free]</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>vm.memory.size[<mode>]</mode></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内存大小字节或百分比<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode - total (默认), active, anon, buffers, cached, exec, file, free, inactive, pinned, shared, wired, used, pused, available<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;监控项vm.memory.size[] 允许三种类型的参数：<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第一类：包含total - 总内存<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第二类： 系统指定内存类型:active, anon, buffers, cached, exec, file, free, inactive,pinned, shared, wired.<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第三类：用户级别，一共使用了多少内存，还有多少内存可用: used, pused, available,pavailable.</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>web.page.get[host,<path></path>,<port>]</port></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;获取网页内容网页源代码<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;host - 主机名/域名<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;path - 文件地址，默认/<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;port - 端口，默认80返回空字符串表示失败. 例如: web.page.get[</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>web.page.perf[host,<path></path>,<port>]</port></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;获取完全加载网页消耗的时长秒，返回0表示失败<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;host - 主机名/域名<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;path - html地址，默认是/<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;port - 端口,默认80</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>web.page.regexp[host,<path></path>,<port>,<regexp>,<length>,<output>]</output></length></regexp></port></strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在网页中搜索字符串  失败则返回空字符 (不匹配).<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;host - 主机名<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;path - html文件路径 (默认值 /)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;port - 端口 (默认80)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;regexp - GNU正则表达式<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;length - 返回的最大的字符串数量<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;output - 输出格式模板可选项. </p>

	

	

</article>





	<span class="different-posts">📖 <a href="/page/4">more posts</a> 📖</span>



	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
